package com.ctyun.xstore.vod.video.model;

public class VideoFileInfoBean {

	private static final int PART_SIZE_MIN_M = 5;

	private static final int PART_SIZE_MAX_M = 200;

	private static final int M = 1024 * 1024;

	public static final int PART_SIZE_MIN = PART_SIZE_MIN_M * M;

	public static final int PART_SIZE_MAX = PART_SIZE_MAX_M * M;

	public static final int DEFAULT_PART_SIZE = 10 * M;

	private String md5;

	private long fileSize;

	private int partSize = DEFAULT_PART_SIZE;

	public VideoFileInfoBean() {
		super();
	}

	public VideoFileInfoBean(long fileSize, int partSize) {
		this.fileSize = fileSize;
		this.partSize = partSize;
		this.validateParam();
	}

	public String getMd5() {
		return md5;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public long getFileSize() {
		return fileSize;
	}

	public void setFileSize(long fileSize) {
		this.fileSize = fileSize;
	}

	public int getPartSize() {
		return partSize;
	}

	public void setPartSize(int partSize) {
		this.partSize = partSize;
	}

	public void setPartSizeM(int partSizeM) {
		this.partSize = partSizeM * M;
	}

	public Long calculatePartNum() {
		validateParam();
		long quotient = this.fileSize / this.partSize;
		long remainer = this.fileSize % this.partSize;
		return remainer == 0l ? quotient : (quotient + 1);
	}

	public void validateParam() {
		if (this.fileSize <= 0 || this.partSize <= 0) {
			throw new IllegalArgumentException("文件大小和分片大小为必传非空正整数参数，请检查！");
		}
		if (this.partSize < PART_SIZE_MIN) {
			throw new IllegalArgumentException("文件分片大小不能小于 " + PART_SIZE_MIN_M + " M");
		}
		if (this.partSize > PART_SIZE_MAX) {
			throw new IllegalArgumentException("文件分片大小不能大于 " + PART_SIZE_MAX_M + " M");
		}
	}

}
